package util.wikiXML.objectModel;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class WikiPage {

	/**
	 * @param args
	 */
	public List section = new LinkedList();
	// public LinkedList categories;
	public List<WikiLink> cross_lingual = new LinkedList<WikiLink>();
	
	//list of links 
	public List<WikiLink> links = new LinkedList<WikiLink>();
	
	
	public List<WikiLink> categories = new LinkedList<WikiLink>();
	

	public HashSet<String> templates = new HashSet<String>();
	
	
	public void  addTemplate (String template){
		
		
		templates.add(template);
		
	} 
	
	
	public String getOutgoingWikis() {

		String t = "";
		Iterator<WikiLink> iter = links.iterator();
		WikiLink l = null;
		if (iter.hasNext()) {

			l = iter.next();
			if (l.getPageName() != null && l.getPageName().length() > 0
					&& !l.getPageName().toLowerCase().startsWith("template:")) {

				t = t + l.getPageName();
			}

		}

		while (iter.hasNext()) {

			l = iter.next();
			if (l.getPageName() != null && l.getPageName().length() > 0
					&& !l.getPageName().toLowerCase().startsWith("template:")) {

				if (t.length() > 1)
					t = t + "\t" + l.getPageName();
				else {

					t = t + l.getPageName();

				}
			}

		}
		return t;

	}
	
	public String getOutgoingAnchorText() {

		String t = "";
		Iterator<WikiLink> iter = links.iterator();
		WikiLink l = null;
		if (iter.hasNext()) {

			l = iter.next();
			if (l.getText() != null && l.getText().length() > 0
					&& !l.getText().toLowerCase().startsWith("template:")) {

				t = t + l.getText().replaceAll("\n", " ");
			}

		}

		while (iter.hasNext()) {

			l = iter.next();
			if (l.getText() != null && l.getText().length() > 0
					&& !l.getText().toLowerCase().startsWith("template:")) {

				if(t.length()>1)
				t = t + "\t" + l.getText().replaceAll("\n", " ");
				else{
					t = t +  l.getText().replaceAll("\n", " ");
					
				}
			}

		}
		return t;

	}
	
	public void addCategory(WikiLink link) {

		categories.add(link);
	}
	
	public String getTemplates() {

		String t = "";

		Iterator<String> iter = templates.iterator();

		if (iter.hasNext()) {
			t = iter.next();

		}
		while (iter.hasNext()) {

			String item = iter.next();

			t = t + "\t" + item;
		}
		return t;

	}

	public String getCategories() {

		String t = "";

		Iterator<WikiLink> iter = categories.iterator();

		if (iter.hasNext()) {
			t = iter.next().getPageName();

		}
		while (iter.hasNext()) {

			String item = iter.next().getPageName();

			t = t + "\t" + item;
		}
		return t;

	}

	private String title;
	private String name;
	private String namespace;

	public String getNamespace() {
		return namespace;
	}

	public void setNamespace(String namespace) {
		this.namespace = namespace;
	}

	private String id;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public WikiPage() {

	}

	public List getSection() {
		return section;
	}

	public List getCross_lingual() {
		return cross_lingual;
	}

	public void setCross_lingual(List cross_lingual) {
		this.cross_lingual = cross_lingual;
	}

	public void setSection(List section) {
		this.section = section;
	}

	public void addSection(WikiContainer container) {
		this.section.add(container);
	}

	public String getArticlenText() {

		StringBuffer string = new StringBuffer("");

		Iterator iterator = section.iterator();
		while (iterator.hasNext()) {

			Object obj = iterator.next();

			if (obj instanceof WikiParagraph) {
				WikiParagraph p = (WikiParagraph) obj;
				string.append(p.getText());

			}

		}

		return string.toString();

	}
	
	
	

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
